<?php
/**
 * @version		$Id: category.php 10752 2008-08-23 01:53:31Z eddieajau $
 * @package		Joomla
 */
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );

jimport('joomla.application.component.model');

/**
 * @package		Joomla
 * @subpackage	download
 * @since 1.5
 */
class IgcategoriesModelIgcategories extends JModel{
	var $_id = null;
	var $_data = null;
	var $_total = null;
	var $_products = null;
	var $_pagination = null;

	function __construct()	{
		parent::__construct();
		global $mainframe;
		$config = JFactory::getConfig();

		//$this->setState('limit', $mainframe->getUserStateFromRequest('com_igallery.limit', 'limit', $config->getValue('config.list_limit'), 'int'));
		$this->setState('limit', 12);
		$this->setState('limitstart', JRequest::getVar('limitstart', 0, '', 'int'));
		$this->setState('limitstart', ($this->getState('limit') != 0 ? (floor($this->getState('limitstart') / $this->getState('limit')) * $this->getState('limit')) : 0));

		$id = JRequest::getVar('cid', 0, '', 'int');	
		$this->setId((int)$id);
	}

	/**
	 * @access	public
	 * @param	int	Category ID number
	 */
	function setId($id){
		// Set category ID and wipe data
		$this->_id			= $id;
		$this->_products	= null;
	}

	/**
	 * @access public
	 * @return array
	 */
	function getData()	{
		if (empty($this->_data))	{
			$query = $this->_buildQuery();
			$this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit'));
			$total = count($this->_data);
			for($i = 0; $i < $total; $i++)			{
				$item =& $this->_data[$i];
				$item->slug = $item->id.':'.$item->alias;
			}
		}
		return $this->_data;
	}
	/**
	 * @access public
	 * @return array
	 */
	function _buildQuery(){
		$query = 'SELECT c.*,p.menu_max_width,p.menu_max_height,p.img_quality,p.crop_menu,p.round_menu,p.round_fill ' .
				' FROM #__igallery AS c LEFT JOIN #__igallery_profiles AS p ON c.profile = p.id' .
				' WHERE c.published = 1  ORDER BY c.ordering ASC ';
				;
		return $query;
	}
	
	function getTotal(){
		if (empty($this->_total)){
			$query = $this->_buildQuery();
			$this->_total = $this->_getListCount($query);
		}

		return $this->_total;
	}

	/**
	 * @access public
	 * @return integer
	 */
	function getPagination(){
		if (empty($this->_pagination)){
			jimport('joomla.html.pagination');
			$this->_pagination = new JPagination( $this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
		}
		return $this->_pagination;
	}
	
	
	
	
}
?>